﻿using System.IO;

namespace Util
{
    /// <summary>
    /// 文件操作工具类
    /// </summary>
    public class FileUtil
    {

        //返回文件后缀名
        public static string getFileExtension(string fileName)
        {
            return Path.GetExtension(fileName).Trim().ToLower();
        }

        //返回资源类型
        //1wmv文件,可以播放 2doc (ppt doc pdf) 3 other 不能预览的exe,rar 大视频如何不能预览也是3
        public static int getResourceType(string fileName)
        {
            int type = 0;
            string extension = getFileExtension(fileName);
            switch (extension)
            {
                case ".doc":
                    type = 2;
                    break;
                case ".pdf":
                    type = 2;
                    break;
                case ".flv":
                    type = 1;
                    break;
                default:
                    type = 3;
                    break;
            }
            return type;
        }

        //重命名文件
        //原文件名_addStr.格式
        public static string renameFile(string filename, string addStr)
        {
            string cutStr = ".";
            string[] s = filename.Split(cutStr.ToCharArray());
            return s[s.Length - 2] + "_" + addStr + "." + s[s.Length - 1];
        }

    }
}
